package com.skyyan.netty.jjf.client.handler;

import cn.hutool.core.util.HexUtil;
import com.skyyan.netty.jjf.client.MessageHandler;
import com.skyyan.netty.jjf.protocol.Message;
import com.skyyan.netty.jjf.protocol.OpenCardMessage;

/**
 * 开卡消息处理器
 */
public class OpenCardMessageHandler implements MessageHandler {
    @Override
    public boolean canHandle(Message msg) {
        return msg instanceof OpenCardMessage;
    }
    
    @Override
    public void handle(Message msg) {
        if (msg instanceof OpenCardMessage.Downlink) {
            OpenCardMessage.Downlink downlink = (OpenCardMessage.Downlink) msg;
            System.out.println("开卡下行报文:");
            System.out.println("  订单号: " + downlink.getOrderId());
            System.out.println("  农户ID: " + HexUtil.encodeHexStr(downlink.getFarmerId()));
            System.out.println("  状态: 0x" + String.format("%02X", downlink.getStatus()));
            System.out.println("  状态描述: " + downlink.getStatusDesc());
        } else {
            System.out.println("开卡上行报文");
        }
    }
}